package com.zxq.lawenf.service.impl;

import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zxq.common.pojo.ApiResponse;
import com.zxq.common.pojo.ApiResponseEnum;
import com.zxq.common.pojo.JSONEnum;
import com.zxq.common.util.ConstatFinalUtil;
import com.zxq.common.util.PageInfoUtil;
import com.zxq.lawenf.dao.IAApprovalDao;
import com.zxq.lawenf.dao.IACaseDao;
import com.zxq.lawenf.dao.IACateDao;
import com.zxq.lawenf.dao.IAHistoryDao;
import com.zxq.lawenf.pojo.AApproval;
import com.zxq.lawenf.pojo.AApprovalEnum;
import com.zxq.lawenf.pojo.ACase;
import com.zxq.lawenf.pojo.ACaseEnum;
import com.zxq.lawenf.pojo.ACate;
import com.zxq.lawenf.pojo.AHistory;
import com.zxq.lawenf.pojo.AHistoryEnum;
import com.zxq.lawenf.service.ILawEnfDbService;

/**
 * 执法模块的Service实现类
 * @author 章晓琦
 */
@Service("lawEnfDbService")
public class LawEnfDbServiceImpl implements ILawEnfDbService
{
	@Resource
	private IACateDao cateDao ;
	@Resource
	private IAApprovalDao approvalDao;
	@Resource
	private IAHistoryDao historyDao;
	@Resource
	private IACaseDao caseDao;
	
	@Override
	public ApiResponse<Object> saveOneCateService(ACate cate)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		Map<String, ACate> data = new HashMap<String, ACate>();
		/* 查询条件 */
		Map<String,Object> condMap=new HashMap<String,Object>();
		
		cate.setCreateTime(new Date());
		cate.setUpdateTime(new Date());
		int res = this.cateDao.save(cate);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), cate.getId());
			data.put(ApiResponseEnum.NAME_ONE.getName(), cate);
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneCateService(ACate cate)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 查询条件 */
		Map<String,Object> condMap=new HashMap<String,Object>();
		
		int res = this.cateDao.update(cate);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), cate.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), cate);
			
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}
	
	@Override
	public ApiResponse<Object> deleteOneCateService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.cateDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ACate> findOneCateService(Map<String, Object> condMap)
	{
		ApiResponse<ACate> apiResponse = new ApiResponse<ACate>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		Map<String, ACate> data = new HashMap<String, ACate>();
		ACate cate = this.cateDao.findOne(condMap);
		
		data.put(ApiResponseEnum.NAME_ONE.getName(), cate);
		
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(cate);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse ; 
	}

	@Override
	public ApiResponse<ACate> findCondListCateService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<ACate> apiResponse = new ApiResponse<ACate>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<ACate> cateList = Collections.EMPTY_LIST;
		
		Map<String, List<ACate>> dataList = new HashMap<String, List<ACate>>();
		/* 对关键字进行模糊匹配 */
		if(condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
		{
			condMap.put("keyword", "%" + condMap.get("keyword") + "%") ; 
		}
		
		/* 设置分页相关信息 */
		if(pageInfoUtil != null)
		{
			/* 设置分页信息 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(),pageInfoUtil.getPageSize());
			cateList = this.cateDao.findList(condMap) ; 
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			/* 向接口中放分页信息 */
			apiResponse.setPageInfoUtil(pageInfoUtil);
		}else
		{
			cateList = this.cateDao.findList(condMap) ; 
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), cateList);
		apiResponse.setDataListJava(cateList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse; 
	}
	
	@Override
	public ApiResponse<Object> saveOneApprovalService(AApproval approval)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		
		approval.setCreateTime(new Date());
		approval.setUpdateTime(new Date());
		int res = this.approvalDao.save(approval);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), approval.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), approval);
			apiResponse.setDataOne(dataMap);
			
			/* 状态变化,要记录日志 */
			AHistory history = new AHistory();
			history.setUsersId(approval.getUsersId());
			history.setAdminsId(approval.getAdminsId());
			history.setRelaId(approval.getId());
			history.setHisType(AHistoryEnum.HISTYPE_APP.getStatus());
			history.setStatus(approval.getStatus());
			history.setContent("申请单状态由:" + approval.getSouStatusStr() + "变为:" + approval.getStatusStr());
			
			history.setCreateTime(new Date());
			history.setUpdateTime(new Date());
			history.setPubTime(new Date());
			
			ApiResponse<Object> historyApiResponse = this.saveOneHistoryService(history);
			ConstatFinalUtil.SYS_LOGGER.info("保存操作历史结果:{}",historyApiResponse.toJSON().toJSONString());
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneApprovalService(AApproval approval)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		approval.setUpdateTime(new Date());
		/* 判断状态 */
		if (approval.getSouStatus() == AApprovalEnum.STATUS_DRAFT.getStatus()
			&& 
			approval.getStatus() == AApprovalEnum.STATUS_DRAFT.getStatus())
		{
			/* 放行 */
			
		}else if (approval.getSouStatus() == AApprovalEnum.STATUS_DRAFT.getStatus()
			&& 
			approval.getStatus() == AApprovalEnum.STATUS_PUBLISHED.getStatus())
		{
			/* 发布 */
			approval.setStatus(AApprovalEnum.STATUS_PUBLISHED.getStatus());
		}else if (approval.getSouStatus() == AApprovalEnum.STATUS_PUBLISHED.getStatus()
				&& 
			approval.getStatus() == AApprovalEnum.STATUS_AUDITSUCCED.getStatus())
		{
			/* 审核通过 */
			approval.setStatus(AApprovalEnum.STATUS_AUDITSUCCED.getStatus());
		}else if (approval.getSouStatus() == AApprovalEnum.STATUS_PUBLISHED.getStatus()
				&& 
			approval.getStatus() == AApprovalEnum.STATUS_FAILED.getStatus())
		{
			/* 审核失败 */
			approval.setStatus(AApprovalEnum.STATUS_FAILED.getStatus());
		}else
		{
			/* 如果都不满足,修改状态无效,会原样返回 */
			/* 说明文件已经上传,无法修改 */
			apiResponse.setCode(ApiResponseEnum.INFO_STATUS_ERROR.getStatus());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
			return apiResponse;
		}
		
		int res = this.approvalDao.update(approval);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), approval.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), approval);
			apiResponse.setDataOne(dataMap);
			
			
			/* 状态变化的时候,要插入一条日志 */
			if(approval.getSouStatus() != approval.getStatus())
			{
				/* 状态变化,要记录日志 */
				AHistory history = new AHistory();
				history.setUsersId(approval.getUsersId());
				history.setAdminsId(approval.getAdminsId());
				history.setRelaId(approval.getId());
				history.setStatus(approval.getStatus());
				history.setHisType(AHistoryEnum.HISTYPE_APP.getStatus());
				history.setContent("申请单状态由:" + approval.getSouStatusStr() + "变为:" + approval.getStatusStr());
				
				history.setCreateTime(new Date());
				history.setUpdateTime(new Date());
				history.setPubTime(new Date());
				
				ApiResponse<Object> historyApiResponse = this.saveOneHistoryService(history);
				ConstatFinalUtil.SYS_LOGGER.info("保存操作历史结果:{}",historyApiResponse.toJSON().toJSONString());
			}
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneApprovalService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.approvalDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<AApproval> findCondListApprovalService(PageInfoUtil pageInfoUtil , Map<String, Object> condMap)
	{
		ApiResponse<AApproval> apiResponse = new ApiResponse<AApproval>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<AApproval> ApprovalList = Collections.EMPTY_LIST;
		
		Map<String, List<AApproval>> dataList = new HashMap<String, List<AApproval>>();
		/* 对关键字进行模糊匹配 */
		if(condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
		{
			condMap.put("keyword", "%" + condMap.get("keyword") + "%") ; 
		}
		
		/* 设置分页相关信息 */
		if(pageInfoUtil != null)
		{
			/* 设置分页信息 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(),pageInfoUtil.getPageSize());
			ApprovalList = this.approvalDao.findList(condMap) ; 
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			/* 向接口中放分页信息 */
			apiResponse.setPageInfoUtil(pageInfoUtil);
		}else
		{
			ApprovalList = this.approvalDao.findList(condMap) ; 
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), ApprovalList);
		
		apiResponse.setDataListJava(ApprovalList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse; 
	}

	@Override
	public ApiResponse<AApproval> findOneApprovalService(Map<String, Object> condMap)
	{
		ApiResponse<AApproval> apiResponse = new ApiResponse<AApproval>();
			
		Map<String, AApproval> data = new HashMap<String, AApproval>();
		AApproval approval = this.approvalDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), approval);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(approval);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse ; 
	}
	
	@Override
	public ApiResponse<Object> saveOneHistoryService(AHistory history)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		
		history.setCreateTime(new Date());
		history.setUpdateTime(new Date());
		int res = this.historyDao.save(history);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), history.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), history);
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneHistoryService(AHistory history)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		history.setUpdateTime(new Date());
		int res = this.historyDao.update(history);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), history.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), history);
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneHistoryService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.historyDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<AHistory> findCondListHistoryService(PageInfoUtil pageInfoUtil , Map<String, Object> condMap)
	{
		ApiResponse<AHistory> apiResponse = new ApiResponse<AHistory>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<AHistory> HistoryList = Collections.EMPTY_LIST;
		
		Map<String, List<AHistory>> dataList = new HashMap<String, List<AHistory>>();
		/* 对关键字进行模糊匹配 */
		if(condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
		{
			condMap.put("keyword", "%" + condMap.get("keyword") + "%") ; 
		}
		
		/* 设置分页相关信息 */
		if(pageInfoUtil != null)
		{
			/* 设置分页信息 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(),pageInfoUtil.getPageSize());
			HistoryList = this.historyDao.findList(condMap) ; 
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			/* 向接口中放分页信息 */
			apiResponse.setPageInfoUtil(pageInfoUtil);
		}else
		{
			HistoryList = this.historyDao.findList(condMap) ; 
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), HistoryList);
		
		apiResponse.setDataListJava(HistoryList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse; 
	}

	@Override
	public ApiResponse<AHistory> findOneHistoryService(Map<String, Object> condMap)
	{
		ApiResponse<AHistory> apiResponse = new ApiResponse<AHistory>();
			
		Map<String, AHistory> data = new HashMap<String, AHistory>();
		AHistory history = this.historyDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), history);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(history);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse ; 
	}
	
	@Override
	public ApiResponse<Object> saveOneCaseService(ACase case1)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		
		case1.setCreateTime(new Date());
		case1.setUpdateTime(new Date());
		int res = this.caseDao.save(case1);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), case1.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), case1);
			apiResponse.setDataOne(dataMap);
			
			/* 状态变化,要记录日志 */
			AHistory history = new AHistory();
			history.setUsersId(case1.getUsersId());
			history.setAdminsId(case1.getDepUseId());
			history.setRelaId(case1.getId());
			history.setHisType(AHistoryEnum.HISTYPE_CASE.getStatus());
			history.setStatus(case1.getStatus());
			history.setContent("申请单状态由:" + case1.getSouStatusStr() + "变为:" + case1.getStatusStr());
			
			history.setCreateTime(new Date());
			history.setUpdateTime(new Date());
			history.setPubTime(new Date());
			
			ApiResponse<Object> historyApiResponse = this.saveOneHistoryService(history);
			ConstatFinalUtil.SYS_LOGGER.info("保存操作历史结果:{}",historyApiResponse.toJSON().toJSONString());
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneCaseService(ACase case1)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		
		/* 判断状态 */
		if (case1.getSouStatus() == ACaseEnum.STATUS_DRAFT.getStatus()
			&& 
			case1.getStatus() == ACaseEnum.STATUS_DRAFT.getStatus())
		{
			/* 放行 */
			
		}else if (case1.getSouStatus() == ACaseEnum.STATUS_DRAFT.getStatus()
			&& 
			case1.getStatus() == ACaseEnum.STATUS_PUBLISHED.getStatus())
		{
			/* 发布 */
			case1.setStatus(ACaseEnum.STATUS_PUBLISHED.getStatus());
		}else if (case1.getSouStatus() == ACaseEnum.STATUS_PUBLISHED.getStatus()
				&& 
			case1.getStatus() == ACaseEnum.STATUS_AUDIT_DEPART.getStatus())
		{
			/* 部门审批 */
			case1.setStatus(ACaseEnum.STATUS_AUDIT_DEPART.getStatus());
		}else if (case1.getSouStatus() == ACaseEnum.STATUS_AUDIT_DEPART.getStatus()
				&& 
			case1.getStatus() == ACaseEnum.STATUS_AUDIT_BUREAU.getStatus())
		{
			/* 局审批 */
			case1.setStatus(ACaseEnum.STATUS_AUDIT_BUREAU.getStatus());
		}else if (case1.getSouStatus() == ACaseEnum.STATUS_AUDIT_BUREAU.getStatus()
				&& 
			case1.getStatus() == ACaseEnum.STATUS_AUDIT_FINISH.getStatus())
		{
			/* 局审批 */
			case1.setStatus(ACaseEnum.STATUS_AUDIT_FINISH.getStatus());
		}else
		{
			/* 如果都不满足,修改状态无效,会原样返回 */
			/* 说明文件已经上传,无法修改 */
			apiResponse.setCode(ApiResponseEnum.INFO_STATUS_ERROR.getStatus());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
			return apiResponse;
		}
		
		case1.setUpdateTime(new Date());
		int res = this.caseDao.update(case1);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), case1.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), case1);
			apiResponse.setDataOne(dataMap);
			
			/* 状态变化要记录日志 */
			if(case1.getSouStatus() != case1.getStatus() )
			{
				/* 状态变化,要记录日志 */
				AHistory history = new AHistory();
				history.setUsersId(case1.getUsersId());
				history.setAdminsId(case1.getDepUseId());
				history.setRelaId(case1.getId());
				history.setHisType(AHistoryEnum.HISTYPE_CASE.getStatus());
				history.setStatus(case1.getStatus());
				history.setContent("申请单状态由:" + case1.getSouStatusStr() + "变为:" + case1.getStatusStr());
				
				history.setCreateTime(new Date());
				history.setUpdateTime(new Date());
				history.setPubTime(new Date());
				
				ApiResponse<Object> historyApiResponse = this.saveOneHistoryService(history);
				ConstatFinalUtil.SYS_LOGGER.info("保存操作历史结果:{}",historyApiResponse.toJSON().toJSONString());
			}
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneCaseService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.caseDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ACase> findCondListCaseService(PageInfoUtil pageInfoUtil , Map<String, Object> condMap)
	{
		ApiResponse<ACase> apiResponse = new ApiResponse<ACase>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<ACase> caseList = Collections.EMPTY_LIST;
		
		Map<String, List<ACase>> dataList = new HashMap<String, List<ACase>>();
		/* 对关键字进行模糊匹配 */
		if(condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
		{
			condMap.put("keyword", "%" + condMap.get("keyword") + "%") ; 
		}
		
		/* 设置分页相关信息 */
		if(pageInfoUtil != null)
		{
			/* 设置分页信息 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(),pageInfoUtil.getPageSize());
			caseList = this.caseDao.findList(condMap) ; 
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			/* 向接口中放分页信息 */
			apiResponse.setPageInfoUtil(pageInfoUtil);
		}else
		{
			caseList = this.caseDao.findList(condMap) ; 
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), caseList);
		
		apiResponse.setDataListJava(caseList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse; 
	}

	@Override
	public ApiResponse<ACase> findOneCaseService(Map<String, Object> condMap)
	{
		ApiResponse<ACase> apiResponse = new ApiResponse<ACase>();
			
		Map<String, ACase> data = new HashMap<String, ACase>();
		ACase case1 = this.caseDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), case1);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(case1);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse ; 
	}
}
